package com.ashlikun.flutter_anim_test

import ExampleHostApi
import FlutterError
import MessageData
import MessageFlutterApi
import io.flutter.plugin.common.BinaryMessenger

/**
 * 作者　　: 李坤
 * 创建时间: 2025/2/12　14:50
 * 邮箱　　：496546144@qq.com
 *
 * 功能介绍：
 */
//提供方法给Flutter调用
class MyHostApi : ExampleHostApi {
    override fun getHostLanguage(): String {
        return "kotlin"
    }

    override fun add(a: Long, b: Long): Long {
        return a + b
    }

    override fun sendMessage(message: MessageData, callback: (Result<Boolean>) -> Unit) {
        if (message.code == 1L) {
            callback(Result.failure(FlutterError("code", "message", "details")))
            return
        }
        callback(Result.success(true))
    }
}
//调用Flutter方法
class PigeonFlutterApi(binaryMessenger: BinaryMessenger) {
    var flutterApi: MessageFlutterApi? = null

    init {
        flutterApi = MessageFlutterApi(binaryMessenger)
    }

    fun callFlutterMethod(aString: String, callback: (Result<String>) -> Unit) {
        flutterApi!!.flutterMethod(aString) { echo -> callback(echo) }
    }
}